/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkg;

import CRUD.ThreadHome;
import Utility.ThreadOperationsUtility;
import Utility.Utility;
import java.util.Iterator;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import xmlMapping.Post;

/**
 *
 * @author Mostafa
 */
public class DisplayPostsTagHandler extends SimpleTagSupport {
    private int threadid;

    /**
     * Called by the container to invoke this tag. 
     * The implementation of this method is provided by the tag library developer,
     * and handles all tag processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        
        try {
 
           xmlMapping.Thread t= new ThreadOperationsUtility().getThread(threadid);
            
            String result="";
      result+="<div id=\"p6\" class=\"codebox bg1\"  ><div class=\"inner\"><span class=\"corners-top\"><span></span></span>"
      +"<div class=\"postbody\">	<h3 class=\"first\"><a href=\"#p6\">t"+t.getTitle()+"</a></h3>"
      + "<p class=\"author\"><a href=\"viewtopic.html\"><img src=\"imageset/icon_post_target.gif\" width=\"11\" height=\"9\" alt=\"Post\" title=\"Post\" /></a>by <strong>"
      + "<a href=\"./memberlist.php?mode=viewprofile&amp;u=2\" style=\"color: #AA0000;\" class=\"username-coloured\">"+t.getMember().getUserName()+"</a></strong> &raquo; "+t.getLastModified()+" </p>"
   + "<div class=\"content\">"+t.getBody()+"</div><div id=\"sig6\" class=\"signature\">This is just a test signature.</div></div>"
   + "<dl class=\"postprofile\" id=\"profile6\"><dt><a href=\"memberlist.html\"><img src=\"download/file.php?avatar=2_1287019645.jpg\" width=\"80\" height=\"80\" alt=\"User avatar\" /></a><br />"
    + "<a href=\"memberlist.html\" style=\"color: #AA0000;\" class=\"username-coloured\">"+t.getMember().getUserName()+"</a></dt>	<dd>Site Admin</dd><dd>&nbsp;</dd><dd><strong></strong> </dd><dd>"
    + "<strong></strong> </dd></dl><a href=\"#\">Delete</a> <br><a href=\"EditThread.jsp?threadId="+t.getThreadId()+"\">Edit</a><div class=\"back2top\"><a href=\"#wrap\" class=\"top\" title=\"Top\">Top</a></div>"
    + "<span class=\"corners-bottom\"><span></span></span></div></div>";
      
     Iterator itr= t.getPosts().iterator();
     
            while (itr.hasNext()) {
               Post p=(Post)itr.next();
                             
                 
               
            result+=   "<br> <br>  <div id=\"p6\" class=\"post bg2\"  ><div class=\"inner\"><span class=\"corners-top\"><span></span></span>"
      +"<div class=\"postbody\">	<h3 class=\"first\"><a href=\"#p6\">"+p.getTitle()+"</a></h3>"
      + "<p class=\"author\"><a href=\"viewtopic.html\"><img src=\"imageset/icon_post_target.gif\" width=\"11\" height=\"9\" alt=\"Post\" title=\"Post\" /></a>by <strong>"
      + "<a href=\"./memberlist.php?mode=viewprofile&amp;u=2\" style=\"color: #AA0000;\" class=\"username-coloured\">"+p.getMember().getUserName()+"</a></strong> &raquo; "+p.getLastModified()+" </p>"
   + "<div class=\"content\">"+p.getBody()+"</div><div id=\"sig6\" class=\"signature\">This is just a test signature.</div></div>"
   + "<dl class=\"postprofile\" id=\"profile6\"><dt><a href=\"memberlist.html\"><img src=\"download/file.php?avatar=2_1287019645.jpg\" width=\"80\" height=\"80\" alt=\"User avatar\" /></a><br />"
    + "<a href=\"memberlist.html\" style=\"color: #AA0000;\" class=\"username-coloured\">"+p.getMember().getUserName()+"</a></dt>	<dd></dd><br><br>";
     String sus ="";
        String ban ="";
        String mod ="";
        boolean suspend = true;
        boolean bann = true ;
        boolean moderator = false ;  //moderator or reqular member
        if(suspend)
          sus = "Unsuspend";
        else
          sus = "Suspend";

        if(bann)
          ban = "Unban";
        else
          ban = "Ban";

        if(moderator)
           mod = "demote";
        else
          mod = "Promote";

        
             result += "<dd> <a href=\"#\">"+sus+"</a><br/><a href=\"#\">"+ban+"</a><br/><a href=\"#\">send Msg</a><br/><a href=\"#\">"+mod+"</a></dd>";
          result+=" <dd>&nbsp;</dd><dd><strong>Posts:</strong> 27</dd><dd><strong>Joined:</strong> Mon Oct 11, 2010 7:55 am</dd>"
                  + "</dl><a href=\"#\">Delete</a> <br><a href=\"#\">Edit</a></br><a href=\"#\">Move</a></br><a href=\"#\">Split</a><div class=\"back2top\"><a href=\"#wrap\" class=\"top\" title=\"Top\">Top</a></div>"
                  + "	<span class=\"corners-bottom\"><span></span></span></div></div>	<hr class=\"divider\" />";         
                    
                    
                    }
      
      
      
      out.println(result);
        } catch (java.io.IOException ex) {
            throw new JspException("Error in DisplayPostsTagHandler tag", ex);
        }
    }

    public void setThreadid(int threadid) {
        this.threadid = threadid;
    }
}
